import { defineStore } from 'pinia'

import { getSetting, getDict } from 'jax-node/api/admin'

export const useAppStore = defineStore('appStore', () => {
  const config = reactive({})
  const dict = reactive({})

  const init = () => {
    getSetting().then(res => {
      for (const key in res) {
        config[key] = res[key]
      }
    })

    getDict().then(res => {
      for (const key in res) {
        dict[key] = res[key]
      }
    })
  }

  return {
    config,
    dict,
    init,
  }
})

export default useAppStore
